<template>
	<div class="publishFrom">
		<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
			<div class="publishFrom_up">
				<el-form-item label="选择视频" prop="imageUrl">
					<div class="publishFrom_ box">
						<el-upload
						  class="avatar-uploader"
						  action="https://jsonplaceholder.typicode.com/posts/"
						  :show-file-list="false"
						  :on-success="handleAvatarSuccess"
						  :before-upload="beforeAvatarUpload">
						  <img v-if="ruleForm.imageUrl" :src="ruleForm.imageUrl" class="avatar">
						  <div class="publishFrom_b" v-else >
						  		<i class="ipm image_up"></i>
						  		<p>点击上传视频</p>
						  		<p>支持MP4/rmvb/mkv/avi格式</p>
						  </div>
						</el-upload>
					</div>
				</el-form-item>
				<el-form-item label="封面图片" prop="imageUrl2">
					<div class="publishFrom_ box">
						<el-upload
						  class="avatar-uploader"
						  action="https://jsonplaceholder.typicode.com/posts/"
						  :show-file-list="false"
						  :on-success="handleAvatarSuccess"
						  :before-upload="beforeAvatarUpload">
						  <img v-if="ruleForm.imageUrl2" :src="ruleForm.imageUrl2" class="avatar">
						  <div class="publishFrom_b" v-else >
						  		<i class="ipm image_up"></i>
						  		<p> 点击上传封面</p>
						  		<p>支持jpg/png/jpegi格式</p>
						  </div>
						</el-upload>
					</div>
				</el-form-item>
			</div>
			<el-form-item label="视频名称" prop="videoName">
				<el-input v-model="ruleForm.videoName" placeholder="请输入视频名称"></el-input>
			</el-form-item>
			<ul>
				<li class="publishFrom_seleck">
					<el-form-item label="授课老师" prop="teacher">
						<el-select v-model="ruleForm.teacher" filterable placeholder="请选择">
							<el-option label="qiu_m" value="1"></el-option>
							<el-option label="qiu_m2" value="2"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="视频信息" prop="videoinfn">
						<el-select v-model="ruleForm.videoinfn" filterable placeholder="请选择">
							<el-option label="公开课" value="1"></el-option>
							<el-option label="微课" value="2"></el-option>
						</el-select>
					</el-form-item>
				</li>
				<!--  -->
				<li class="publishFrom_seleck">
					<el-form-item label="学段" prop="period">
						<el-select v-model="ruleForm.period" filterable placeholder="请选择">
							<el-option label="小学" value="1"></el-option>
							<el-option label="初中" value="2"></el-option>
							<el-option label="高中" value="3"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="年级" prop="grade">
						<el-select v-model="ruleForm.grade" filterable placeholder="请选择">
							<el-option label="一年级" value="1"></el-option>
							<el-option label="二年级" value="2"></el-option>
						</el-select>
					</el-form-item>
				</li>
				<!--  -->
				<li class="publishFrom_seleck">
					<el-form-item label="科目" prop="subject">
						<el-select v-model="ruleForm.subject" filterable placeholder="请选择">
							<el-option label="语文" value="1"></el-option>
							<el-option label="数学" value="2"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="版本" prop="version">
						<el-select v-model="ruleForm.version" filterable placeholder="请选择">
							<el-option label="人教版" value="1"></el-option>
							<el-option label="粤教版" value="2"></el-option>
						</el-select>
					</el-form-item>
				</li>
				<!--  -->
				<li class="publishFrom_seleck">
					<el-form-item label="教材" prop="material">
						<el-select v-model="ruleForm.material" filterable placeholder="请选择">
							<el-option label="语文" value="1"></el-option>
							<el-option label="数学" value="2"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="章" prop="chapter">
						<el-select v-model="ruleForm.chapter" filterable placeholder="请选择">
							<el-option label="第一章" value="1"></el-option>
							<el-option label="第二章" value="2"></el-option>
						</el-select>
					</el-form-item>
				</li>
				<!--  -->
				<li class="publishFrom_seleck">
					<el-form-item label="节" prop="section">
						<el-select v-model="ruleForm.section" filterable placeholder="请选择">
							<el-option label="一节" value="1"></el-option>
							<el-option label="二节" value="2"></el-option>
						</el-select>
					</el-form-item>
				</li>
			</ul>
			<el-form-item label="关键字" prop="keyword">
				<el-input v-model="ruleForm.keyword" placeholder="请输入视频关键字"></el-input>
			</el-form-item>
			<el-form-item label="视频简介" prop="synopsis">
				<el-input type="textarea" 
				:rows="5" resize="none"
				v-model="ruleForm.synopsis"
				placeholder="请输入视频简介,不超200字"></el-input>
				<span class="numberWord"><i>{{ ruleForm.synopsis.length }}</i>/200</span>
			</el-form-item>
			<el-form-item label="课程须知" prop="notice">
				<el-input type="textarea" 
				v-model="ruleForm.notice" 
				:rows="5" resize="none"
				placeholder="课程须知,不超200字"></el-input>
				<span class="numberWord"><i>{{ ruleForm.notice.length }}</i>/200</span>
			</el-form-item>
			<el-form-item label="允许下载" prop="class">
				<el-radio-group v-model="ruleForm.class">
					<el-radio label="1">是</el-radio>
					<el-radio label="0">否</el-radio>
				</el-radio-group>
			</el-form-item>
		
			<div class="information clear">
				<div class="information_l fl">
					<span>
						<i class="ipm but_Collection02_down"></i>
						<p>700收藏</p>
					</span>
					<span>
						<i class="ipm but_Collection02_down"></i>
						<p>1900播放</p>
					</span>
					<span>
						<i class="ipm but_Collection02_down"></i>
						<p>5000评论</p>
					</span>
				</div>
				<div class="information_r fr">
					<p>视频得分<strong>98</strong></p>
					<p>上传于  2017-10-25  20:16</p>
				</div>
			</div>
			<el-form-item class="buttonCSS">
				<el-button @click="resetForm('ruleForm')" type="primary" plain>取消</el-button>
				<el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	
	export default {
		name: '',
		data() {
			return {
				activeIndex: '1',
				ruleForm: {
					videoName: '', //视频名称
					teacher: '', //授课老师
					videoinfn: '', //视频信息
					period: '', //学段
					grade: '', //年级
					subject: '', //科目
					version: '', // 版本
					material: '', //教材
					chapter: '', //章
					section: '', //节
					keyword: '', //关键字
					synopsis: '', //视频简介
					notice: '', //课程须知
					creditVal: '', //学分-自定义
					imageUrl2:'',
					imageUrl: '',
				},
				rules: {
					videoName: [
						{ required: true, message: '请输入视频名称', trigger: 'blur' },
						{ min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
					],
					teacher: [
						{ required: false, message: '请选择授课老师', trigger: 'change' }
					],
					videoinfn: [
						{ required: true, message: '请选择视频信息', trigger: 'change' }
					],
					period: [
						{ required: true, message: '请选择活学段', trigger: 'change' }
					],
					grade: [
						{ required: true, message: '请选择年级', trigger: 'change' }
					],
					subject: [
						{ required: true, message: '请选择科目	', trigger: 'change' }
					],
					version: [
						{ required: true, message: '请选择版本', trigger: 'change' }
					],
					material: [
						{ required: false, message: '请选择教材', trigger: 'change' }
					],
					chapter: [
						{ required: false, message: '请选择章', trigger: 'change' }
					],
					section: [
						{ required: false, message: '请选择节', trigger: 'change' }
					],
					synopsis: [
						// { required: true, message: '请填写活动形式', trigger: 'blur' },
						{ min: 0, max: 10, message: '长度在 0 到 200 个字符', trigger: 'change' }
					],
					notice: [
						// { required: true, message: '请填写活动形式', trigger: 'blur' },
						{ min: 0, max: 200, message: '长度在 0 到 200 个字符', trigger: 'change' }
					],
					imageUrl: [
						{ required: true, message: '请选择教材', trigger: 'change' }
					],
					imageUrl2: [
						{ required: true, message: '请选择教材', trigger: 'change' }
					]
				}
			}
		},
		computed: {
		
		},
		methods: {
			//上传
			handleAvatarSuccess(res, file) {
                // res.data =  res.data.data;
				this.imageUrl = URL.createObjectURL(file.raw);
			},
			beforeAvatarUpload(file) {
			},
			//表单验证
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {

						this.$notify({
							title: '',
							customClass: 'notify_day',
							dangerouslyUseHTMLString: true,
							message: '<div><i class="ipm face"></i>操作成功</div>'
						});
					} else {
						return false;
					}
				});
			},
			resetForm(formName) {
				this.$refs[formName].resetFields();
			},
		}
	}
</script>